<?php

namespace app\index\model;

use think\Model;

class ExpenditureBills extends Model
{
    public $map = [];
    public $fields = '*';
    public $p = 1;
    public $limit = 15;

    public function initialize()
    {
        parent::initialize();
        $this->map['status'] = ['neq','0'];
    }

    public function getList()
    {
        return $this->field($this->fields)->where($this->map)
            ->order('bill_create_time desc')
            ->page($this->p,$this->limit)
            ->select();
    }

    public function getAll()
    {
        return $this->field($this->fields)->where($this->map)
            ->order('bill_create_time desc')
            ->select();
    }

    public function getPaymentRank($type)
    {
        $this->map =  [
            'status' => ['neq','0'],
            'income_or_disburse' => '支出'
        ];

        $year = input('param.year',date('Y'));
        $month = input('param.month',date('m'));
        $day = date('t', strtotime($year . '-' .$month));

        if($type == 'year')
        {
            $this->map['bill_create_time'] = [
                'between' , ["{$year}-01-01 00:00:00", "{$year}-12-31 23:59:59"]
            ];
        }
        else if($type == 'all')
        {
            // pass
        }
        else
        {
            $this->map['bill_create_time'] = [
                'between' , ["{$year}-{$month}-01 00:00:00", "{$year}-{$month}-{$day} 23:59:59"]
            ];
        }
        return $this->field($this->fields)->where($this->map)
            ->order('amount_money desc')->limit(0, 10)
            ->select();
    }

}